<template>
  <el-input-number
    ref="elInputNumber"
    v-model="formValue"
    v-bind="$attrs"
    v-on="$listeners"
    @focus="handleFocus"
  />
</template>

<script>
export default {
  name: "form-input-number",
  model: {
    prop: "value", // 绑定的值，通过父组件传递
    event: "update",
  },
  props: {
    value: {
      type: [String, Number],
      default: "",
    },
  },
  computed: {
    formValue: {
      get() {
        return this.value;
      },
      set(val) {
        this.$emit("update", val);
      },
    },
  },
  methods: {
    handleFocus() {
      // 在这里编写失去焦点时想要执行的代码
      if (this.$attrs.readonly) this.$refs.elInputNumber.$refs.input.blur();
    },
  },
};
</script>

<style lang="scss" scoped></style>
